<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // if语句
        if (5 > 3) {
            console.log(`5>3 = true`);
        } else {
            console.log(`5 >3 = false`)
        }

        // while循环
        let i = 1;
        while (i <= 5) {
            console.log("循环执行了" + (i++) + "次");
        }

        // break 和continue
        // break用于跳出内层循环，
        // continue用于跳过本次循环
        for (let i = 0; i < 4; i++) {
            if (i == 2) {
                continue; // 跳过下面的语句，直接执行i++
            }
            for (let j = 0; j < 10; j++) {
                if (j == 5) {
                    break; // 跳出for循环，直接执行 i++
                }
                console.log(`i=${i},j=${j}`);
            }
        }

        // 遍历对象for/in

        let a = {
            id: 0,
            name: "孙悟空",
            age: 1000
        }

        for (key in a) {
            console.log(`key is ${key} and value is ${a[key]}`);
        }

        // null对象或者{}对象或者显示声明undefined，都可以用for/in，而不报错,但是如果为声明，则报错Uncaught ReferenceError: b is not defined
        // let b = null 
        // let b = {}
        //    遍历window对象，取key
        for (key in window) {
            console.log(`key is ${key} and value is ${window[key]} `);
        }

        // 遍历集合for/of,如list,set,map,(数组，集合，映射)和字符串，取值,注意不能对对象进行，否则报ncaught TypeError: arr is not iterable
        // let arr = [1, 3, 4, 5];
        // let arr = {}
        // 同样，如果为空串，空数组，不报错，如果不声明，则报错
        let arr = ""
        for (v of arr) {
            console.log(`value of arr is ${v}`);
        }



    </script>
</body>

</html>